package com.longy.gulimall.order.service.impl;

import com.longy.gulimall.order.config.OrderThreadPoolExecutor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Async;
import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.Map;
import java.util.Random;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.longy.common.utils.PageUtils;
import com.longy.common.utils.Query;

import com.longy.gulimall.order.dao.OrderDao;
import com.longy.gulimall.order.entity.OrderEntity;
import com.longy.gulimall.order.service.OrderService;


@Service("orderService")
@Slf4j
public class OrderServiceImpl extends ServiceImpl<OrderDao, OrderEntity> implements OrderService {

    @Autowired
    OrderThreadPoolExecutor orderThreadPool;

    @Override
    public PageUtils queryPage(Map<String, Object> params) {
        IPage<OrderEntity> page = this.page(
                new Query<OrderEntity>().getPage(params),
                new QueryWrapper<OrderEntity>()
        );

        return new PageUtils(page);
    }

    @Override
    @Async("orderThreadPool")
    public void asyncTask() {
//        ThreadPoolTaskExecutor pool = orderThreadPool.getPool();
//        pool.submit(() ->{
        log.info("test--asyncTask--start");
            try {
                for (int i = 0; i < 200; i++) {
                    HashMap<Object, Object> objectObjectHashMap = new HashMap<>();
                    objectObjectHashMap.put(i,"asda");
                }
                Random random = new Random();
                int i = random.nextInt(10);
                Thread.sleep(100);
            } catch (InterruptedException e) {
                throw new RuntimeException(e);
            }
//        });
    }

}